package com.xja.controller;

import com.xja.pojo.CourseInfo;
import com.xja.service.BlogService;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @作者:褚
 * @工程名:xja_blog
 * @方法:ToolController
 * @创建时间:2022/4/21 22:13
 */
@Controller
@RequestMapping("tool")
public class ToolController {

    private Logger logger= LoggerFactory.getLogger(BlogController.class);
    @Reference(url = "dubbo://localhost:20883")
    private BlogService blogService;
    @RequestMapping("active")
    private String active(){
        return "active";
    }
    @RequestMapping("community")
    private String community(Model model,@RequestParam(value = "counts",defaultValue = "0") Integer counts){
         counts=counts+2;
        CourseInfo courseInfo = new CourseInfo();
        courseInfo.setCount(counts);
        List<CourseInfo> courseInfoList = blogService.getCourseInfoList(courseInfo);
        List<CourseInfo> hostCourseInfoList =null;
        if (courseInfoList.size()<4){
            hostCourseInfoList = courseInfoList.subList(0, courseInfoList.size());
        }else {
            hostCourseInfoList = courseInfoList.subList(0, 4);
        }
        model.addAttribute("counts",counts);
        model.addAttribute("courseInfoList",courseInfoList);
        model.addAttribute("hostCourseInfoList",hostCourseInfoList);
        return "community";
    }
    @RequestMapping("contact")
    private String contact(){
        return "contact";
    }
}
